package com.ebai.product.management.model.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.ebai.product.management.base.cache.service.PublicCacheImpl;

@Entity
@Table(name = "t_global_user")
public class User extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    //@GeneratedValue(generator = "paymentableGenerator")
    //@GenericGenerator(name = "paymentableGenerator", strategy = "guid")
    @GeneratedValue(generator="idGenerator")
    @GenericGenerator(name="idGenerator", strategy="uuid")
    @Column(name = "PID", length = 36)
    private String pid;

    @Column(name = "LOGIN_NAME", length = 32)
    private String loginName;

    @Column(name = "LOGIN_PASSWD", length = 32)
    private String loginPasswd;

    @Column(name = "USER_NAME", length = 255)
    private String userName;

    @Column(name = "MOBILE_NO", length = 11)
    private String mobileNo;

    @Column(name = "IS_ENABLE", length = 50)
    private String isEnable;

    @Column(name = "IS_DELETE", length = 50)
    private String isDelete;
    
    @ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name = "t_global_user_dept", joinColumns = { @JoinColumn(name = "USER_PID") },
				inverseJoinColumns = { @JoinColumn(name = "DEPT_PID") })
	private List<Dept> depts;
    
    @ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name = "t_global_role_user", joinColumns = { @JoinColumn(name = "USER_PID") },
				inverseJoinColumns = { @JoinColumn(name = "ROLE_PID") })
	private List<Role> roles;

    @Transient
    private String isEnableText;
    
    @Transient
    private String roleName;
    
    @Transient
    private String deptName;

    public String getIsEnableText() {
        return PublicCacheImpl.showDictText("TYSF", this.isEnable);
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getLoginPasswd() {
        return loginPasswd;
    }

    public void setLoginPasswd(String loginPasswd) {
        this.loginPasswd = loginPasswd;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getMobileNo() {
        return mobileNo;
    }

    public void setMobileNo(String mobileNo) {
        this.mobileNo = mobileNo;
    }

    public String getIsEnable() {
        return isEnable;
    }

    public void setIsEnable(String isEnable) {
        this.isEnable = isEnable;
    }

    public String getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(String isDelete) {
        this.isDelete = isDelete;
    }

	public List<Dept> getDepts() {
		return depts;
	}

	public void setDepts(List<Dept> depts) {
		this.depts = depts;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public String getRoleName() {
		//return roleName;
		if (null != this.roles && this.roles.size()>0) {
			return this.roles.get(0).getRoleName();
		}
		
		return "";
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getDeptName() {
		//return deptName;
		if (null != this.depts && this.depts.size()>0) {
			return this.depts.get(0).getDeptName();
		}
		
		return "";
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}
	
}
